<template>
  <div>
    <el-table
      :data="goods.slice((currentPage-1)*pageSize,currentPage*pageSize)"
      style="width: 100%"
    >
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="店铺名称">
              <span>{{ props.row.name }}</span>
            </el-form-item>
            <el-form-item label="店铺介绍">
              <span>{{ props.row.description }}</span>
            </el-form-item>
            <el-form-item label="联系电话">
              <span>{{ props.row.phone }}</span>
            </el-form-item>
            <el-form-item label="销售量">
              <span>{{ props.row.recent_order_num }}</span>
            </el-form-item>
            <el-form-item label="店铺地址">
              <span>{{ props.row.address }}</span>
            </el-form-item>
            <el-form-item label="店铺ID">
              <span>{{ props.row.status }}</span>
            </el-form-item>
            <el-form-item label="评分">
              <span>{{ props.row.rating }}</span>
            </el-form-item>
            <el-form-item label="分类">
              <span>{{ props.row.category }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="店铺名称" width="150" align="center"></el-table-column>
      <el-table-column prop="address" label="店铺地址" width="250" align="center"></el-table-column>
      <el-table-column prop="description" label="店铺介绍" width="150" align="center"></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini">编辑</el-button>
          <el-button size="mini">添加商品</el-button>
          <el-button
            size="mini"
            type="danger"
            @click.native.prevent="deleteRow(scope.$index, goods)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-size="pageSize"
      layout="total,sizes,prev,pager,next,jumper"
      :total="100"
    ></el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentPage: 1,
      pageSize: 5
    };
  },
  mounted() {
    this.$store.dispatch("GOODS_DATA");
  },
  methods: {
    handleSizeChange(val) {
      console.log(`每页${val}条`);
      this.pagesize = val;
    },
    handleCurrentChange(currentPage) {
      //console.log(`当前页:${val}`);
      this.currentPage = currentPage;
    },
    deleteRow(index, rows) {
      rows.splice(index, 1);
    }
  },
  computed: {
    goodsItme() {
      return this.$store.state.goodsItme;
    },
    goods() {
      return this.$store.state.goods;
    }
  }
};
</script>

<style>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
